package websimulator;

import java.util.*;

public class House 
{
    //Variabler
    private int people;             //antall persojoner som bor i huset
    private int area;               //hus størrelse i kvadratt meter
    private int averagePower;       //gjennomsnitlig strøm forbruk
    private int energyConsumption;  //strøm forbruk per kvadratt meter
    
    private LinkedList <Heating>oppvarmingTime = new LinkedList<Heating>();
    private LinkedList <Illumination>belysningTime = new LinkedList<Illumination>();
    private LinkedList <WaterHeating>waterheatTime = new LinkedList<WaterHeating>();
    private LinkedList <TechniqueEquipment>techniqueEquipmentTime = new LinkedList<TechniqueEquipment>();
    private LinkedList <Ventilation>ventilationTime = new LinkedList<Ventilation>();
    private double techSum = 0;
    
    /**
     * ArrayLister som innholder value som vil brukes i graph
     */
    public ArrayList <Double>heatingforGraph = new ArrayList<Double>();     //oppvarming
    public ArrayList <Double>illuminationGraph = new ArrayList<Double>();   //belysning
    public ArrayList <Double>waterheatingGraph = new ArrayList<Double>();   //vann oppvarming
    public ArrayList <Double>techniqueEquipmentGraph = new ArrayList<Double>(); 
    public ArrayList <Double>ventilationGraph = new ArrayList<Double>();
    
    
    //Temperatur inn og ute som skal brukes i simulering
    public ArrayList <Double>temperaturOut = new ArrayList<Double>();
    public ArrayList <Double>temperaturIn = new ArrayList<Double>();
    public ArrayList <Double>temperaturDifference = new ArrayList<Double>();
    
    //Belysningsnivå i huset
    LevelOfIllumination levelOfIllumination = new LevelOfIllumination();
    public ArrayList <Double> belysningsnivå = new ArrayList<Double>();
    public int directive;   //Sendes videre til heating konstruktør
    public double wallHeight;
    
    /**
     * @param _people antall persojoner som bor i huset
     * @param _area hus størrelse i kvadrat meter
     */
    public House(int _people, int _area)
    {
        Temperatur temperatur = new Temperatur();
        people = _people;
        area = _area;  
        temperaturOut = temperatur.temperaturOutside();
        temperaturIn = temperatur.temperaturInside();
        belysningsnivå = levelOfIllumination.illuminationLevel();
        
        directive = 4;
        wallHeight = 3;
    }
    
    /**
     * Konstruktor til visuel Menu
     * @param _people
     * @param _area
     * @param _tempOut
     * @param _tempIn 
     */
    public House(int _people, int _area, ArrayList<Double> _tempOut, ArrayList<Double> _tempIn, ArrayList<Double> _lys, int _directive, double _wallHeight)
    {
        people = _people;
        area = _area;  
        temperaturOut = _tempOut;
        temperaturIn = _tempIn;
        
        belysningsnivå = _lys;
        directive = _directive;
        wallHeight = _wallHeight;
    }
    
    /**
     * Metode som kaller andre nødvendige metoder til å beregne strømforbruk i huset
     */
    public void Calculation()
    {
        /*
        Illumination belysning = new Illumination(area, 1);
        Heating oppvarming = new Heating(area, 1);
        
        AveragePowerIntake(people, area);
        System.out.println("Gjennomsnittlig energiforbruk");
        
        System.out.println(averagePower);
        System.out.println("Belysning");
        System.out.println(belysning.Calculation());
         System.out.println("Belysning demo:");
        System.out.println(belysning.Demo());
        System.out.println("Oppvarming");
        System.out.println(oppvarming.Demo());
        * 
        */
    }
    
    /**
     * AveragePowerIntake
     * @param _people antall persojoner som bor i huset
     * @param _area hus størrelse i kvadratt meter
     * @return gjennomsnitlig strøm forbruk
     */
    private int AveragePowerIntake(int _people, int _area)
    {
        if(_people == 1)
        {
            energyConsumption = 177;//Statistikk informasjon fra "Statistisk sentralbyrå"
        }
        else if (_people == 2 || _people == 3)
        {
            energyConsumption = 183;//Statistikk informasjon fra "Statistisk sentralbyrå"
        }
        else if (_people == 4)
        {
            energyConsumption = 184;//Statistikk informasjon fra "Statistisk sentralbyrå"
        }
        else
        {
            energyConsumption = 191;//Statistikk informasjon fra "Statistisk sentralbyrå"
        }
        
        averagePower = energyConsumption * _area;
       
        return averagePower;
    }//end of AveragePowerIntake

    
    /**
     * @return hus areal i kvadrat meter
     */
    public int getArea()
    {
        return area;
    }

    /**
     * @return antal beboure
     */
    public int getPeople()
    {
        return people;
    }
    //End of get metoder
    
    /**
     * Beregne strøm forbruk til oppvarming per time
     * @return ArrayList av double variable (strøm forbruk til hus oppvarming per time)
     */
    public ArrayList calcHeating()
    {
        for (int i = 0; i < 25; i++)
        {
            oppvarmingTime.add(new Heating(area, 1, directive, temperaturIn.get(i), temperaturOut.get(i), wallHeight, (area / 6), i)); 
        }  
        
        for(int i = 0; i < 25; i++)
        {
            heatingforGraph.add(oppvarmingTime.get(i).CalculationTime());     
        }
        
        return heatingforGraph;
    }
    
    /*
     * Beregner strømforbruk som går til belysning.
     */
    public ArrayList calcIllumination()
    {

        for(int i = 0; i < 25; i++)
        {
            belysningTime.add(new Illumination(area, 3, belysningsnivå.get(i)));
        }
        

        for(int i = 0; i < 25; i++)
        {
            illuminationGraph.add(belysningTime.get(i).CalculationTime());
        }

        return illuminationGraph;
    }
    
    /**
     * Beregner strømforbruk som går til oppvarming av vann
     * @return 
     */
    public ArrayList calcWaterHeating()
    {
        for(int i = 0 ;i < 25 ;i++)
        {
            waterheatTime.add(new WaterHeating(people,1,i));
        }
        
        for(int i=0;i<25;i++)
        {   
            waterheatingGraph.add(waterheatTime.get(i).dayDemonstration());
        }
        return waterheatingGraph;
    }
    
    /**
     * Beregner strøm forbrukk som går til forskjellige ting i huset
     * @return 
     */
    public ArrayList calcTechEquipment()
    {
        //Typisk hus: (skal bruke i demo)
        techniqueEquipmentTime.add(new TechniqueEquipment("Komfyr", 2200, 1));
        techniqueEquipmentTime.add(new TechniqueEquipment("Oppvaskmaskin", 2000, 1));
        techniqueEquipmentTime.add(new TechniqueEquipment("Kaffetrakter", 1500, 0.5));
        techniqueEquipmentTime.add(new TechniqueEquipment("Kjøleskap", 160, 8));
        techniqueEquipmentTime.add(new TechniqueEquipment("Fryseboks", 175, 10));        
        techniqueEquipmentTime.add(new TechniqueEquipment("Vaskemaskin", 2500, 0.6));
        techniqueEquipmentTime.add(new TechniqueEquipment("Tørketrommel", 3000, 0.5));        
        techniqueEquipmentTime.add(new TechniqueEquipment("TV", 100, 4));
        techniqueEquipmentTime.add(new TechniqueEquipment("Stereoanlegg", 25, 4));
        techniqueEquipmentTime.add(new TechniqueEquipment("Støvsuger", 1000, 0.15));
        techniqueEquipmentTime.add(new TechniqueEquipment("Sjermen", 60, 6));
        techniqueEquipmentTime.add(new TechniqueEquipment("PC", 850, 6));
        
        for (int i = 0; i < techniqueEquipmentTime.size(); i++)
        {
            techSum = techSum + techniqueEquipmentTime.get(i).Calculation();
        }
        
        for (int i = 0; i < 25; i++)
        {
            techniqueEquipmentGraph.add(techSum/25);
        }
        
        return techniqueEquipmentGraph;
    }
    
    public ArrayList calcVentilation()
    {
        TempDif();
        for (int i = 0; i < 25; i++)
        {
            ventilationTime.add(new Ventilation(area, wallHeight, temperaturDifference.get(i), 0));
            ventilationGraph.add(ventilationTime.get(i).CalculationTime());
        }  
        
        return ventilationGraph;
    }
    
    private void TempDif()
    {
        for (int i = 0; i < 25; i++)
        {
            if (temperaturOut.get(i) < 0)
                temperaturDifference.add(temperaturIn.get(i) + Math.abs(temperaturOut.get(i)));
            else
                temperaturDifference.add(temperaturIn.get(i) - temperaturOut.get(i));
        } 
    }
    
    
}//end of House
